package com.songyang.mqttandothers.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songyang.mqttandothers.bean.DeviceBean;
import com.songyang.mqttandothers.bean.UserBean;
import com.songyang.mqttandothers.mapper.UserMapper;
import com.songyang.mqttandothers.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserBean> implements UserService {
    @Autowired
    private UserMapper userMapper;

    public Integer login(UserBean userBean) {
        QueryWrapper<UserBean> queryWrapper = new QueryWrapper<UserBean>().eq("user_name", userBean.getUserName()).eq("pass_word", userBean.getPassWord());
        UserBean user = userMapper.selectOne(queryWrapper);
        if (user != null && user.getId() != null) {
            return user.getId();
        }
        return -1;
    }

    @Override
    public boolean register(UserBean userBean) {
        UserBean prepareUser = new UserBean();
        prepareUser.setUserName(userBean.getUserName());
        prepareUser.setPassWord(userBean.getPassWord());
        int insert = userMapper.insert(prepareUser);
        if (insert > 0) return true;
        return false;
    }


}
